//
//  User.swift
//  XMGWeibo
//
//  Created by apple on 15/10/8.
//  Copyright © 2015年 小码哥. All rights reserved.
//

import UIKit

class User: NSObject {
    /// 用户代号
    var id: Int = 0
    /// 显示名称
    var name: String?
    
    /// 用户头像地址（中图），50×50像素
    var profile_image_url: String? {
        didSet {
            if let URLStr = profile_image_url {
                profile_URL = NSURL(string: URLStr)
            }
        }
    }
    /// 用户头像URL
    var profile_URL: NSURL?
    
    /// 是否认证, true是, false不是
    var verified: Bool = false
    /// 用户的认证类型，-1：没有认证，0，认证用户，2,3,5: 企业认证，220: 达人
    var verified_type: Int = -1 {
        didSet {
            switch verified_type {
                // 个人认证
            case 0:
                verified_image = UIImage(named: "avatar_vip")
                // 企业认证
            case 2,3,5:
               verified_image = UIImage(named: "avatar_enterprise_vip")
                // 达人
            case 220:
                verified_image = UIImage(named: "avatar_grassroot")
                // 空图标
            default:
                verified_image  = nil
            }
        }
    }
    /// 用户的认证图标
    var verified_image: UIImage?
    
    /// 会员等级 1~6, 如果不是1~6就不是会员
    var mbrank: Int = -1
        {
        didSet{
            // 1.判断是否是会员
            if mbrank > 0 && mbrank < 7
            {
                vipImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            }
        }
    }
    /// 会员图标图片
    var vipImage: UIImage?
    
    init(dict: [String: AnyObject])
    {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    
    /// 属性字典
    static let properties = ["id", "name", "profile_image_url", "verified", "verified_type"]
    // 打印对象
    override var description: String{
        return "\(self.dictionaryWithValuesForKeys(User.properties))"
    }
}
